﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Exp1._2
{
    public partial class Exp1_2 : Form
    {
        public Exp1_2()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            /*
            string strResult;
            strResult = txtName.Text + "你好！欢迎使用本程序！";
            lblShow.Text = strResult;
             */

            string strName = txtName.Text;
            int count = 0;
            int number = 0;
            try
            {
                foreach (char Re in strName)
                {
                    if (Re >= 'a' && Re <= 'z' || Re > 'A' && Re <= 'Z')
                        number++;
                }

                for (int i = 0; i <= strName.Length; i++)
                {
                    char ch = strName[i];  //获取第i个字符
                    if (ch >= 'a' && ch <= 'z' || ch > 'A' && ch <= 'Z')
                        count++;

                }
                lblShow.Text = string.Format("{0}中有{1}个英文字符", strName, count);
                lblShow.Text += string.Format("foreach计算的个是{0}", number);
            }
            catch(Exception ex)
            {
                lblShow.Text = ex.Message;
                lblShow.Text += string.Format("foreach计算的个是{0}", number);
            }
        }


    }
}
